package com.hqbzl.chat;

import com.hqbzl.chat.annotations.RpcClientService;
import com.hqbzl.chat.constant.Constants;
import com.hqbzl.chat.handler.RpcResponseHandler;
import com.hqbzl.chat.init.ClassInit;
import com.hqbzl.chat.message.RpcRequestMessage;
import com.hqbzl.chat.model.UserInfo;
import com.hqbzl.chat.protocol.MessageCodec;
import com.hqbzl.chat.protocol.ProcotolFramDecoder;
import com.hqbzl.chat.service.UserService;
import com.hqbzl.chat.utils.Helper;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.util.concurrent.DefaultPromise;
import io.netty.util.concurrent.Promise;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

@Slf4j
public class RpcClientManagerEx {

    @RpcClientService
    private UserService service;


    public RpcClientManagerEx() {
        service = Helper.getProxyService(UserService.class);
    }

    public static void main(String[] args) {
//        final UserService service = getProxyService(UserService.class);
//        final String say1 = service.say("a1", "b1");
//        final UserInfo userInfo = service.info("李四");
//        System.out.println("userInfo = " + userInfo);
//        final RpcClientManagerEx rpc = new RpcClientManagerEx();
//        Helper.init(rpc);
//        ClassInit.init(rpc);
//        rpc.service.info("111");
//        final UserService service = getProxyService(UserService.class);
//        service.info("111");
//        System.out.println(service);
//        System.out.println("wait");
        final RpcClientManagerEx rpc = new RpcClientManagerEx();
        final UserInfo abc = rpc.service.info("abc");
        System.out.println("abc = " + abc);
        System.out.println("rpc.service.info(\"abc\") = " + rpc.service.info("abc"));
        System.out.println("rpc.service.info(\"1\") = " + rpc.service.info("1"));
        System.out.println("rpc.service.info(\"2\") = " + rpc.service.info("2"));
        System.out.println("rpc.service.info(\"3\") = " + rpc.service.info("3"));
        System.out.println("rpc.service.info(\"4\") = " + rpc.service.info("4"));
    }


}
